<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #is_show="{ record }">
        <a-switch
          :checked-value="1" 
          unchecked-value="2"
          @change="changeStatus($event, record.id)"
          :default-checked="record.is_show == 1"
        />
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive,onMounted, onActivated, defineProps } from 'vue'
import predictionDfz from '@/api/prediction/predictionDfz'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const props = defineProps({
  info:{
    default:{}
  }
})
onMounted(()=>{
  crudRef.value.requestData()
})
const changeStatus = async (status, id) => {
  const response = await predictionDfz.update(id, {is_show:status })
  if (response.success) {
    Message.success(response.message)
  }
}
const numberOperation = (newValue, id, numberName) => {
  predictionDfz.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  predictionDfz.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_prediction_dfz',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  autoRequest:false,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: predictionDfz.getList,
  recycleApi: predictionDfz.getRecycleList,
  add: {
    show: true,
    api: predictionDfz.save,
    auth: ['prediction:dfz:save']
  },
  edit: {
    show: true,
    api: predictionDfz.update,
    auth: ['prediction:dfz:update']
  },
  delete: {
    show: true,
    api: predictionDfz.deletes,
    auth: ['prediction:dfz:delete'],
    realApi: predictionDfz.realDeletes,
    realAuth: ['prediction:dfz:realDeletes']
  },
  recovery: {
    show: true,
    api: predictionDfz.recoverys,
    auth: ['prediction:dfz:recovery']
  },
  import: {
    show: true,
    url: 'prediction/dfz/import',
    templateUrl: 'prediction/dfz/downloadTemplate',
    auth: ['prediction:dfz:import']
  },
  export: {
    show: true,
    url: 'prediction/dfz/export',
    auth: ['prediction:dfz:export']
  },
  beforeRequest:(params)=>{
    params.tlj_id = props.info.id
  },
  beforeAdd:(params)=>{
    params.tlj_id = props.info.id
    return true
  },
  
})

const columns = reactive([
  {
    title: "到发站管理",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入到发站管理"
    }
  },
  {
    title: "站台名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入站台名称"
    }
  },
  {
    title: "所属铁路局",
    dataIndex: "tlj_id",
    formType: "select",
    addDisplay:false,
    commonRules: {
      required: true,
      message: "请输入所属铁路局"
    },
    dict: {
      url: "prediction/tlj/index",
      params: {
        page: 1,
        pageSize: 500
      },
      props: { label: "name", value: "id" },
      translation: true
    },
  },
  {
    title: "是否显示",
    dataIndex: "is_show",
    formType: "switch",
    commonRules: {
      required: true,
      message: "请输入是否显示"
    }
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'prediction:dfz' } </script>